﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using XFControls.Utils;

namespace XFControls.XFPanels.XFPanelItems
{
    public interface IXFButton
    {
        XFPanelBase Parent { get; set; }
        int Width { get; set; }
        int Height { get; set; }
        event EventHandler Clicked;
        void Click();
        void ButtonPaint(Graphics g, int x, int y);
    }

    public class XFButtonBack : IXFButton
    {
        private int _height = 40;
        private int _width = 40;

        #region IXFButton Members

        public int Width
        {
            get
            {
                return _width;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public int Height
        {
            get
            {
                return _height;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public event EventHandler Clicked;
        public XFPanelBase Parent { get; set; }

        public void Click()
        {
            if (Clicked != null)
                Clicked(this, new EventArgs());

            if (Parent == null)
                return;

            if (Parent is XFPanelHeader)
            {
                var mp = ((XFPanelHeader)Parent).MainPanelContainer;

                var rec = Screen.PrimaryScreen.WorkingArea;

                mp.MainPanel.EnableSlide();

                if (mp.MainPanel.LeftPanel == null || !mp.MainPanel.LeftPanel.HasBack)
                    mp.SetHeaderLeftButton(null);

                mp.MainPanel.Invalidate();
            }
        }

        public void ButtonPaint(Graphics g, int x, int y)
        {
            if (Parent.Height < _height)
            {
                _width /= 2;
                _height /= 2;
            }
            this.DrawUIAlphaChannel("back", g, new Rectangle(x, y, _width, _height));
        }

        #endregion
    }

}
